import 'dart:convert';

import 'package:eplorex/providers/user_context.dart';
import 'package:eplorex/utils/HttpUtil.dart';

import '../models/moment/comment_model.dart';
import '../models/moment/moment_model.dart';

class MomentInfoDao {


  static Future<MomentModel?> fetch(int? momentId) async {
    var response = await HttpUtil.getInstance().get("/api/moment/v1/detail",
        data: {'momentId': momentId, 'userId': UserContext.cxt()!.uid});

    if (response!.statusCode == 200) {
      return MomentModel.fromJson(response.data['data']);
    } else {
      return null;
    }
  }

  static Future<List<CommentModel>?> fetchComment(int? momentId) async {
    final response = await HttpUtil.getInstance().get("/api/comment/v1/list", data: {
      'momentId': momentId,
    });

    if (response!.statusCode == 200) {
      return (response.data['data'] as List)
          .map((e) => CommentModel.fromJson(e as Map<String, dynamic>))
          .toList();
    } else {
      return null;
    }
  }

  static Future<void> likeMoment(num? momentId,bool like) async {
    final response = await HttpUtil.getInstance().post('/api/moment/v1/like', data: jsonEncode({
      'userId':UserContext.cxt()!.uid,
      'like':like,
      'momentId': momentId,
    }));
    if (response!.statusCode == 200) {
    } else {
    }
  }
}
